package com.cssw.fyzb.web.controller;


import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.web.dto.FeedbackDto;
import com.cssw.fyzb.web.dto.GExchangeFDto;
import com.cssw.fyzb.web.dto.RnbExchangeFDto;
import com.cssw.fyzb.web.dto.YExchangeFDto;
import com.cssw.fyzb.web.service.ExchangeDefService;
import com.cssw.fyzb.web.service.FuncService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@ApiModel("兑换配置表")
@RestController
@RequestMapping("/exchangeDef")
public class ExchangeDefController {
    @Autowired
    ExchangeDefService exchangeDefService;

    @ApiOperation(value = "音值转福币配置列表", response = AjaxPage.class)
    @RequestMapping(value = "/yList", method = RequestMethod.GET)
    public AjaxPage yList(int page, int limit) {
        Map param = new HashMap();
        return exchangeDefService.yList(1, 10, param);
    }

    @ApiOperation(value = "音值转福币删除", response = AjaxData.class)
    @PostMapping(value = "/yDelete")
    public AjaxData yDelete(@RequestBody YExchangeFDto dto) {
        boolean result = exchangeDefService.yDelete(dto.getYfId(),UserContext.getUserId());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }

    @ApiOperation(value = "音值转福币修改", response = AjaxData.class)
    @PostMapping(value = "/yUpdate")
    public AjaxData yUpdate(@RequestBody YExchangeFDto dto) {
        boolean result = false;
        if(dto.getYfId() == null)
            result = exchangeDefService.yAdd(dto.getYCoin(),dto.getFCoin(),UserContext.getUserId());
        else
            result = exchangeDefService.yUpdate(dto.getYfId(),dto.getYCoin(),dto.getFCoin(),UserContext.getUserId());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }

    @ApiOperation(value = "音值转福币添加", response = AjaxData.class)
    @PostMapping(value = "/yAdd")
    public AjaxData yAdd(@RequestBody YExchangeFDto dto) {
        boolean result = exchangeDefService.yAdd(dto.getYCoin(),dto.getFCoin(),UserContext.getUserId());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }


    @ApiOperation(value = "果子转福币配置列表", response = AjaxPage.class)
    @RequestMapping(value = "/gList", method = RequestMethod.GET)
    public AjaxPage gList(int page, int limit) {
        Map param = new HashMap();
        return exchangeDefService.gList(1, 10, param);
    }

    @ApiOperation(value = "果子转福币删除", response = AjaxData.class)
    @PostMapping(value = "/gDelete")
    public AjaxData gDelete(@RequestBody GExchangeFDto dto) {
        boolean result = exchangeDefService.gDelete(dto.getYfId(),UserContext.getUserId());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }

    @ApiOperation(value = "果子转福币修改", response = AjaxData.class)
    @PostMapping(value = "/gUpdate")
    public AjaxData yUpdate(@RequestBody GExchangeFDto dto) {
        boolean result = false;
        if(dto.getYfId() == null)
            result = exchangeDefService.gAdd(dto.getGCoin(),dto.getFCoin(),UserContext.getUserId());
        else
            result = exchangeDefService.gUpdate(dto.getYfId(),dto.getGCoin(),dto.getFCoin(),UserContext.getUserId());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }

    @ApiOperation(value = "果子转福币添加", response = AjaxData.class)
    @PostMapping(value = "/gAdd")
    public AjaxData gAdd(@RequestBody GExchangeFDto dto) {
        boolean result = exchangeDefService.gAdd(dto.getGCoin(),dto.getFCoin(),UserContext.getUserId());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }


    @ApiOperation(value = "福币管理", response = AjaxPage.class)
    @RequestMapping(value = "/rnbList", method = RequestMethod.GET)
    public AjaxPage rnbList(int page, int limit) {
        Map param = new HashMap();
        return exchangeDefService.rnbList(1, 10, param);
    }

    @ApiOperation(value = "福币管理删除", response = AjaxData.class)
    @PostMapping(value = "/rnbDelete")
    public AjaxData yDelete(@RequestBody RnbExchangeFDto dto) {
        boolean result = exchangeDefService.rnbDelete(dto.getRfId(),UserContext.getUserId());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }

    @ApiOperation(value = "福币管理修改", response = AjaxData.class)
    @PostMapping(value = "/rnbUpdate")
    public AjaxData yUpdate(@RequestBody RnbExchangeFDto dto) {
        boolean result = false;
        if(dto.getRfId() == null)
            result = exchangeDefService.rnbAdd(dto.getRnb(),dto.getFCoin(),UserContext.getUserId());
        else
            result = exchangeDefService.rnbUpdate(dto.getRfId(),dto.getRnb(),dto.getFCoin(),UserContext.getUserId());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }

    @ApiOperation(value = "音值转福币添加", response = AjaxData.class)
    @PostMapping(value = "/rnbAdd")
    public AjaxData yAdd(@RequestBody RnbExchangeFDto dto) {
        boolean result = exchangeDefService.rnbAdd(dto.getRnb(),dto.getFCoin(),UserContext.getUserId());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }
}
